package cn.zh.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 自动配置类
 *
 * @author 白羊
 * @date 2021/12/24
 */
@Configuration
@EnableSwagger2
public class SwaggerAutoConfiguration {

    @Bean
    public Docket createRestApiOne() {
        //docket对象用于封装接口文档信息
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //.groupName("用户接口组")
                .select()
                //.apis(RequestHandlerSelectors.basePackage("cn.zh.controller.user"))
                .apis(RequestHandlerSelectors.basePackage("cn.zh.controller"))
                .build();
        return docket;
    }

//    @Bean
//    public Docket createRestApiTwo() {
//        //docket对象用于封装接口文档信息
//        Docket docket = new Docket(DocumentationType.SWAGGER_2)
//                .apiInfo(apiInfo())
//                .groupName("菜单接口组")
//                .select()
//                .apis(RequestHandlerSelectors.basePackage("cn.zh.controller.menu"))
//                .build();
//        return docket;
//    }

    //构建 api文档的详细信息
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("API接口文档") //页面标题
                .contact(new Contact("搬砖小浩浩", "", "")) //创建人
                .version("1.0") //版本号
                .description("API 描述") //描述
                .build();
    }
}
